import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hsh/brick/widget/text_widget.dart';
import 'package:flutter_hsh/fluttergromore/ads/ads_const.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../brick/widget/basic_widget.dart';
import '../../routes/app_pages.dart';
import '../../style/style.dart';
import '../ads/ad_feed_view.dart';
import '../config/app_const.dart';

class PrivacyWidget extends StatefulWidget {
  final Function() onTapYes;
  final Function() onTapNo;

  const PrivacyWidget({
    super.key,
    required this.onTapNo,
    required this.onTapYes,
  });

  @override
  State<PrivacyWidget> createState() => _PrivacyWidgetState();
}

class _PrivacyWidgetState extends State<PrivacyWidget> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      body: Center(
        child: WillPopScope(
          onWillPop: () async {
            return false;
          },
          child: StatefulBuilder(
            builder: (context, state) {
              return SingleChildScrollView(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Stack(
                      children: [
                        Column(mainAxisSize: MainAxisSize.min, children: [
                          UIColumn(
                              margin: EdgeInsets.symmetric(
                                  horizontal: 12.w, vertical: 12.w),
                              padding: EdgeInsets.fromLTRB(0, 0, 0.w, 8.w),
                              mainAxisSize: MainAxisSize.min,
                              width: Get.width * 0.9,
                              color: Colors.white,
                              radius: 25.w,
                              children: [
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    UIText(
                                      text: "隐私保护指引概要",
                                      textColor: kAppColor("#000000"),
                                      fontSize: 19.sp,
                                      fontWeight: FontWeight.w600,
                                      alignment: Alignment.center,
                                      padding:
                                          EdgeInsets.symmetric(vertical: 20.w),
                                    ),
                                  ],
                                ),
                                // UIText(
                                //   alignment: Alignment.centerLeft,
                                //   text:
                                //       "亲爱的用户 ${widget.businessId.isNotEmpty ? "(${widget.businessId})" : ""}：",
                                //   margin: EdgeInsets.symmetric(horizontal: 24.w),
                                //   fontWeight: FontWeight.w600,
                                //   textColor: kAppColor("#000000"),
                                //   fontSize: 15.sp,
                                // ),
                                UIColumn(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  margin: EdgeInsets.symmetric(horizontal: 0.w),
                                  children: [
                                    Text.rich(
                                      style: const TextStyle(height: 1.5),
                                      TextSpan(
                                        text: '请你务必审慎阅读、充分理解:\n',
                                        style: TextStyle(
                                            fontSize: 14.sp,
                                            color: const Color(0xFF333333)),
                                        children: [
                                          TextSpan(
                                            text: '《用户协议》',
                                            style: TextStyle(
                                                fontSize: 14.sp,
                                                color: kAppColor("#FF0245FF")),
                                            recognizer: TapGestureRecognizer()
                                              ..onTap = () {
                                                Get.toNamed(Routes.webView,
                                                    arguments: {
                                                      "webUrl":
                                                          AppConst.serviceUrl,
                                                      "title": "用户协议"
                                                    });
                                              },
                                          ),
                                          TextSpan(
                                              text: '及',
                                              style: TextStyle(
                                                fontSize: 14.sp,
                                              )),
                                          TextSpan(
                                            text: '《隐私政策》',
                                            style: TextStyle(
                                                fontSize: 14.sp,
                                                color: kAppColor("#FF0245FF")),
                                            recognizer: TapGestureRecognizer()
                                              ..onTap = () {
                                                Get.toNamed(Routes.webView,
                                                    arguments: {
                                                      "webUrl":
                                                          AppConst.policyUrl,
                                                      "title": "隐私政策"
                                                    });
                                              },
                                          ),
                                          TextSpan(
                                            text:
                                                '各条款，包括但不限于：为了向你提供服务，我们需要收集你的设备信息、操作日志等个人信息。获取相关功能使用权限。你可阅读“用户协议”和“隐私政策”了解详细信息。如你同意请点击“同意并继续”开始接受我们的服务。',
                                            style: TextStyle(
                                              fontSize: 14.sp,
                                            ),
                                          ),
                                        ],
                                      ),
                                    ).paddingAll(16),
                                  ],
                                ),
                                UIColumn(
                                  height: 50.w,
                                  onTap: () {
                                    Get.back();
                                    widget.onTapYes();
                                  },
                                  gradientStartColor: kAppColor("#FF0D6FFF"),
                                  gradientEndColor: kAppColor("#FF0D6FFF"),
                                  radius: 25,
                                  alignment: Alignment.center,
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  margin:
                                      EdgeInsets.fromLTRB(30.w, 0.w, 30.w, 0),
                                  children: [
                                    UIText(
                                      text: "同意并继续",
                                      textColor: kAppColor("#FFFFFF"),
                                      fontSize: 16.sp,
                                    )
                                  ],
                                ),
                                UIText(
                                    onTap: () {
                                      Get.back();
                                      widget.onTapNo();
                                    },
                                    text: "不同意",
                                    textColor: kAppColor("#FFCCCCCC"),
                                    fontSize: 16.sp,
                                    alignment: Alignment.center,
                                    margin: EdgeInsets.fromLTRB(
                                        4.w, 10.w, 4.w, 10.w)),
                                // ClipRRect(
                                //   borderRadius: BorderRadius.circular(12.0),
                                //   // 设置圆角的大小
                                //   child: Center(
                                //     child: widget.showFeed
                                //         ? FeedAdsPage()
                                //         : Container(),
                                //   ),
                                // ),
                              ])
                        ]),
                        // Positioned(
                        //   right: 10,
                        //   top: 10,
                        //   child: MyImage(
                        //     margin: EdgeInsets.symmetric(
                        //         horizontal: 12.w, vertical: 12.w),
                        //     'ic_privacy_look.png',
                        //     isAssetImage: true,
                        //     height: 80,
                        //   ),
                        // )
                      ],
                    ),
                    const MyAdFeedView()
                  ],
                ),
              );
            },
          ),
        ),
      ),
    );
  }
}
